package org.bee.service;

import jakarta.annotation.Resource;
import org.bee.mappers.RolePermissionMapper;
import org.bee.model.RolePermission;
import org.bee.model.RolePermissionExample;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RolePermissionService {
    @Resource
    private RolePermissionMapper rolePermissionMapper;

    public void deleteByRoleId(String roleId) {
        RolePermissionExample example = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        rolePermissionMapper.deleteByExample(example);
    }

    public void saveRolePermission(String id, String elementId) {
        RolePermission rolePermission = new RolePermission();
        rolePermission.setRoleId(id);
        rolePermission.setPermissionId(elementId);
        rolePermissionMapper.insert(rolePermission);
    }

    public List<RolePermission> selectByPermissionId(String permissionId){
        RolePermissionExample example = new RolePermissionExample();
        RolePermissionExample.Criteria criteria = example.createCriteria();
        criteria.andPermissionIdEqualTo(permissionId);
        return rolePermissionMapper.selectByExample(example);
    }

}
